package com.nchu.service.impl;

import com.nchu.mappers.OrderMapper;
import com.nchu.pojo.Filter;
import com.nchu.pojo.OrderComplain;
import com.nchu.pojo.OrderForm;
import com.nchu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<OrderForm> FindAllbyid(int userid) {
        return orderMapper.FindAllbyid(userid);
    }

    public List<OrderForm> FindPickUpOrdersByid(int userid) {
        return orderMapper.FindPickUpOrdersByid(userid);
    }

    public List<OrderForm> FindAllbyidandstatus(int userid, int status) {
        return orderMapper.FindAllbyidandstatus(userid,status);
    }

    public List<OrderForm> FindAllbyreceiveUserandstatus(int userid, int status) {
        return orderMapper.FindAllbyreceiveUserandstatus(userid,status);
    }

    @Override
    public int addOrder(OrderForm orderForm) {
        try {
            orderForm.setOrderStatus(2);
            orderMapper.addOrder(orderForm);
        }
        catch (Exception e){
            e.printStackTrace();
            return 0;
        }
        return 1;
    }
    @Autowired
    private OrderMapper mapper;
    public List<OrderComplain> Qurry(int complainantid) {
        return mapper.Qurry(complainantid);
    }

    public List<OrderComplain> Find(int respondentid) {
        return mapper.Find(respondentid);
    }

    public int AddComplain(int orderid, int complainantid, int respondentid, String complain) {
        return orderMapper.AddComplain(orderid,complainantid,respondentid,complain);
    }
    public int InsertOrderReceivingUserAndChangeOrderStatus(int orderID, int userID){
        try{
            orderMapper.InsertOrderReceivingUserAndChangeOrderStatus(orderID,userID);
            return 1;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    public int changebyid(int orderid, String remark, int status) {
        return mapper.changebyid(orderid,remark);
    }

    public OrderForm FindByOrderid(int orderid) {
        return orderMapper.FindByOrderid(orderid);
    }

    public List<OrderComplain> queryByOrderId(int orderid) {
        return orderMapper.queryByOrderId(orderid);
    }

    @Override
    public List<OrderForm> queryAllOrderForms() {
        return mapper.queryAllOrders();
    }

    @Override
    public List<OrderForm> queryOrderFormsByLimit(Filter filter) {
        return mapper.queryOrderFormsByLimit(filter);
    }

    public int deletebyorderid(int orderid) {
        return mapper.deletebyorderid(orderid);
    }

    public int finishorder(int orderid) {
        OrderForm orderForm = mapper.FindByOrderid(orderid);
        mapper.OrderSettlement(orderForm);
        return mapper.finishorder(orderid);
    }

    public OrderForm findone(int orderid){
        return mapper.findone(orderid);
    };
//    public User popup(int orderid){
//        return mapper.popup(orderid);
//    };


    public int updatacomplainstatus(int orderid) {
        return mapper.updatacomplainstatus(orderid);
    }

    ;
    public int updataOrderTransationstatus(int orderid){
        return mapper.updataOrderTransationstatus(orderid);
    };
}
